//
//  ApiViewController.swift
//  NewLndd
//
//  Created by 邵禹曦 on 2020/1/2.
//  Copyright © 2020 辽宁当代. All rights reserved.
//

import UIKit
import Alamofire
// 我的部分接口处理层
class ApiViewController: BaseViewController {

    var u : String?
    var retcode : String?
    var user : User?

    override func viewDidLoad() {
        super.viewDidLoad()

    }
        
    override func loadView() {
        super.loadView()
    }
        
}

extension ApiViewController {

        
    // 用户验证
    func _network(str : [String], group: DispatchGroup)->Bool {
        group.enter()
        NetworkTools.share.check_user(code: str as Array<Any>) { (result, error) in
            
            if error != nil {
                print("no no no")
                return
            }

            if Int(self._retcode(res: result!))! < 0 {
                self.isLogin = false
            } else {
                self.isLogin = true
            }
            group.leave()
        }
        return self.isLogin
    }
    
    // 出入金用户验证
    func crj_network(str : [String], group: DispatchGroup)->Bool {
        group.enter()
        NetworkTools.share.crj_check_user(code: str as Array<Any>) { (result, error) in
            
            if error != nil {
                print("no no no")
                return
            }

            if Int(self._retcode(res: result!))! < 0 {
                self.isLogin = false
            } else {
                self.isLogin = true
            }
            group.leave()
        }
        return self.isLogin
    }
        
        
        
    // 获取retcode
    func _retcode(res : [String : AnyObject]) -> String {
        var result : [String : AnyObject] = [:]
        if let _rep = res["REP"] as? [String : AnyObject] {
            result = (_rep["RESULT"] as? [String : AnyObject])!
        }
        return result["RETCODE"] as! String
    }
    
    
    // 加密 changeEncode
    func psdCode(str : String){
        /*
        //http://39.98.72.212:8007/index.php?str=lndd1601&state=0
        //let url = "http://39.98.72.212:8007/index.php?str=" + str + "&state=0"
        
        let para : [String : String] = ["state" : "0"]

        AlamofireRequest.requestData(.GET, URLString: "http://39.98.72.212:8007/index.php?str=" + str, parameters: para) { (result) in
            print(result)
        }*/
        
        
        
    }
        
}
